<template>
  <div class="printForm">
    <div class="area-header">
      <span class="area-header-title">{{ $t('物资明细') }}</span>
    </div>
    <table class="printTable">
      <tr>
        <td class="tit">{{ $t('标题') }}</td>
        <td colspan="3">{{ form.actTitle }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('申请人') }}</td>
        <td>
          <UserSelect
            v-model="form.applicant"
          />
        </td>
        <td class="tit">{{ $t('申请时间') }}</td>
        <td>{{ parseTime(form.applicationTime) }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('申请部门') }}</td>
        <td>
          <DeptSelect v-model="form.deptId" :placeholder="$t('申请部门')" />
        </td>
        <td class="tit">{{ $t('缓急') }}</td>
        <td>
          <dict-select
            v-model="form.hurry"
            dictionary="urgency_type"
            :placeholder="$t('缓急')"
          />
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('密级') }}</td>
        <td>
          <dict-select
            v-model="form.degreeSecrets"
            dictionary="secrets_type"
            :placeholder="$t('密级')"
          />
        </td>
        <td class="tit">{{ $t('预计金额（元）') }}</td>
        <td>
          {{ moneyFormat(form.estimatedAmount) }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('事项') }}</td>
        <td colspan="3">{{ form.matter }}</td>
      </tr>

    </table>

    <!-- 附件列表 -->
    <FileView :list.sync="form.fileList" data-type="purchase_apply" />

  </div>
</template>

<script>
import { getOaPurchaseApply } from '@/api/oa/purchaseApply/oaPurchaseApply'
import { getFdSubjectList } from '@/api/fd/config/getTypeMain'

export default {
  components: {
  },
  data() {
    return {
      // 表单参数
      form: {
        // 当前用户
        userId: undefined,
        // 附件列表
        fileList: [],
        oaExpenseList: []
      },
      // 费用类型
      getFdSubjectList: []
    }
  },
  created() {
    // 费用类型
    getFdSubjectList('expense').then(response => {
      this.getFdSubjectList = this.changeSubjectList(response.data)
    })
  },
  mounted() {
    this.$bus.$emit('async_done')
  },
  methods: {
    changeSubjectList(val) {
      const arr = []
      if (val.length !== 0) {
        val.forEach(item => {
          const obj = {}
          obj.value = item.value
          obj.label = this.$t(item.label)
          if (item.children && item.children.length > 0) {
            obj.children = this.changeSubjectList(item.children)
          }
          arr.push(obj)
        })
      }
      return arr
    },
    // 初始化数据
    init(data) {
      if (data != null && data !== '' && data.id !== undefined) {
        getOaPurchaseApply(data.id).then(response => {
          this.form = response.data
        })
      } else {
        this.reset()
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        userId: this.$store.state.user.userId,
        applyTime: new Date(),
        amountMoney: undefined,
        costsThat: undefined,
        actId: undefined,
        actStatus: '',
        remark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        payCompletionTime: undefined,
        delFlag: undefined,
        oaExpenseList: [],
        fileList: undefined,
        getFdSubjectList: []
      }
      this.resetForm('form')
    }

  }
}
</script>

